<?php
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 xoops.org                           //
//                       <http://www.xoops.org/>                             //
//  ------------------------------------------------------------------------ //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //
// Author: Dirk Herrmann (Alfred)                                            //
// Site: http://www.simple-xoops.de                                          //
// Project: The XOOPS Project                                                //
// ------------------------------------------------------------------------- //
if( ! defined( 'XOOPS_ROOT_PATH' ) ) die("XOOPS_ROOT_PATH not defined!");
include_once dirname(dirname(__FILE__))."/include/xoops.php";
include_once dirname(dirname(__FILE__))."/seo_plugin.php";
if (!function_exists("info_navblock_edit")) {
  function info_navblock_edit($options) {
      global $xoopsDB;
	  $module_name = basename( dirname(dirname( __FILE__ ))) ;
	  $sql="SELECT catid,title FROM ".$xoopsDB->prefix($module_name.'_cat')." ORDER BY title";
	  $result=$xoopsDB->query($sql);
	  if ($result && $xoopsDB->getRowsNum($result)>0) {
	      $form = "" . _INFO_BL_OPTION . "&nbsp;&nbsp;";
		  $form .= "<input type='hidden' name='options[0]' value='".$module_name."'>";
		  $form .= "<select name='options[1]' size='1'>";
		  while ($row=$xoopsDB->fetcharray($result)) {
              $form .= "<option value='".$row['catid']."'";
			  if ($options[1] == $row['catid']) $form .= " selected";
			  $form .="> " . $row['title'] . " </option>";
		  }
		  $form .= "</select>";
		  $form .= "<br />" . _INFO_BL_OPTION1 . "&nbsp;&nbsp;";
		  $form .= "<select name='options[2]' size='1'>";
		  $form .= "<option value='dynamisch'";
		  if (isset($options[2]) && $options[2] == 'dynamisch') $form .= " selected";
		  $form .="> " . _INFO_BL_OPTION2 . " </option>";
		  $form .= "<option value='fest'";
		  if (isset($options[2]) && $options[2] == 'fest') $form .= " selected";
		  $form .="> " . _INFO_BL_OPTION3 . " </option>";
		  $form .= "<option value='dhtml'";
		  if (isset($options[2]) && $options[2] == 'dhtml') $form .= " selected";
		  $form .="> " . _INFO_BL_OPTION4 . " </option>";
		  $form .= "</select>";
          return $form;
	  }
  }
}


if (!function_exists("info_block_nav")) {
  function info_block_nav($options) {
    global $xoopsDB, $xoopsModule, $xoopsTpl, $xoopsUser,$xoopsConfig;
	global $xoopsRequestUri,$module_handler,$config_handler;
	global $id,$pid,$cat;
	if (!is_object($module_handler)) $module_handler =& xoops_gethandler('module');
	include_once XOOPS_ROOT_PATH."/modules/".$options[0]."/include/xoops.php";
	require_once XOOPS_ROOT_PATH."/class/xoopstree.php";
	//Variablen erstellen
	$block = array();
	if (empty($options)) return $block;
	$groups =  ($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS); 		
	$myts =& MyTextSanitizer::getInstance();
	require_once dirname(dirname(__FILE__))."/seo_plugin.php";
    $InfoModule = $module_handler->getByDirname($options[0]);
	$InfoModuleConfig = $config_handler->getConfigsByCat(0, $InfoModule->getVar('mid'));
	$seo = (!empty($InfoModuleConfig[$options[0].'_seourl']) && $InfoModuleConfig[$options[0].'_seourl']>0) ? intval($InfoModuleConfig[$options[0].'_seourl']) : 0;
	$info_tree = new XoopsTree($xoopsDB->prefix($options[0]), "storyid", "parent_id");
	if (is_object($xoopsModule) && $xoopsModule->dirname() == $options[0] && basename($_SERVER['SCRIPT_NAME']) == "index.php") {	
	  //Modul ist aktiv
	  $info_status = true;
	} else {
	  // ausserhalb des Modules
	  $info_status = false;
	}
	if ($info_status) {
	  $cP = $info_tree->getAllParentId($id,"blockid",array("0",$id));
	  $cAllList = $info_tree->getAllChild(0,"blockid");
	} else {
	  $sql = "SELECT storyid,homepage FROM ".$xoopsDB->prefix($options[0])." WHERE address ='".$xoopsRequestUri."'";
	  $merg = $xoopsDB->query($sql);
	  $mlist = false;
	  if ($merg && $xoopsDB->getRowsNum($merg)>0) {
	    // Eintrag gefunden
		$row = $xoopsDB->fetchArray($merg);
		$id = intval($row['storyid']);
		//$cat = intval($row['homepage']);
		$mlist = true;
		unset($merg);
	  } else {
	    if (!empty($_SESSION['navi_info_id'])) {
		  $id = intval($_SESSION['navi_info_id']);
		  $mlist = true;
		  unset($_SESSION['navi_info_id']);
		}
	  }
	  if ($mlist==false) {
	    $cP = array("0");
	    $cAllList = $info_tree->getFirstChild(0,"blockid");
	  } else {
	    $cP = $info_tree->getAllParentId($id,"blockid",array("0",$id));
	    $cAllList = $info_tree->getAllChild(0,"blockid");
	  }
	}	
	$cPlist=array();
	foreach ($cAllList as $tc) {
	  if ($tc['homepage']==$options[1]) array_push($cPlist, $tc);
	}
		
	foreach ($cPlist as $tcontent) {
	  $visible=0;
	  $vsgroup=array();
	  $vsgroup=explode (",", $tcontent['visible_group']);
	  $vscount=count($vsgroup)-1;		
	  while ($vscount > -1){
		if (in_array($vsgroup[$vscount], $groups)) $visible = 1;
		$vscount--;
      }
	  if (isset($options[2]) && $options[2]=="dhtml") {
		 // todo
	  } elseif (isset($options[2]) && $options[2]!="fest") {
		if (!in_array($tcontent['parent_id'],$cP)) $visible=0;
	  }
	  if ($tcontent['st']!=1) $visible=0; // ???
	  if (intval($tcontent['visible'])!=1) $visible = 0;
	  if ($visible==1) {
	    $link = array();
		$xuid = ($xoopsUser) ? $xoopsUser->getVar('uid') : 0;
		$tcontent['address']=str_replace("{xuid}",$xuid,$tcontent['address']);  //automatisch generierte uid
		$link['id'] = $tcontent['storyid'];
		$link['title'] = $tcontent['title']; 
		$link['parent'] = $tcontent['parent_id'];
		$mode=array("seo"=>$seo,"id"=>$tcontent['storyid'],"title"=>$tcontent['title'],"dir"=>$options[0],"cat"=>$tcontent['homepage']);
		eval ('$ctURL = seo_plugin_'.$options[0].'_make($mode);');
		if ($tcontent['parent_id'] >0)
		  $link['currentParent'] = str_repeat ("&nbsp;&nbsp;", count($info_tree->getAllParentId($tcontent['storyid'])));
		else
		  $link['currentParent'] = "";		
		if ($tcontent['link'] == 1) { //int.Link
		  if (substr($tcontent['address'],-1) =="/" || substr($tcontent['address'],-1) =="\\") $tcontent['address'].="index.php";
		  //$link['target'] = (intval($tcontent['self']) == 1) ? "_blank" : "_self";
	    } elseif ($tcontent['link'] == 2) { // ext.Link
		  $ok = (substr($tcontent['address'],0,4)=="http" || substr($tcontent['address'],0,3)=="ftp") ? 1:0;
		  if ($ok==1) $contentURL = $tcontent['address'];
		  //$link['target'] = (intval($tcontent['self']) == 1) ? "_blank" : "_self";
		} elseif ($tcontent['link'] == 3) {
		  $mode=array("seo"=>$seo,"id"=>$tcontent['storyid'],"title"=>$tcontent['title'],"dir"=>$options[0],"cat"=>'p'.$tcontent['homepage']);
		  eval ('$ctURL = seo_plugin_'.$options[0].'_make($mode);');
		  $link['kategorie'] = '1';
		  $link['click'] = $tcontent['click'];
		} 
		
		$link['address'] = $ctURL;
		if ($tcontent['tooltip'] != "") {
		  $tooltext = strip_tags ($tcontent['tooltip']);
		  $link['tooltip'] = $tooltext;
		} else {
		  $link['tooltip'] = $link['title'];
		}
		$link['aktiv'] = ( $tcontent['storyid'] == $id ) ? 1 : 0;
		$block['links'][] = $link;
		unset($link);
	  }
	}   
	return $block;
  }
}
?>